]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
portalHelper: Schedule recheck if it's too soon to recheck
authorMichael Catanzaro <mcatanzaro@redhat.com>
Sun, 27 Jul 2025 14:40:51 +0000 (16:40 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Sat, 13 Sep 2025 16:54:43 +0000 (18:54 +0200)
Currently we have a 30 second limit on rechecks. A recheck that would
violate the limit is simply dropped. This causes the portal helper to
never close itself.

Instead, schedule a future recheck for as soon as the timeout expires.
This will put an upper bound on how long the portal helper will
unnecessarily remain open.

(I've also changed the logic to unconditionally emit CANCELLED in
vfunc_close_request(), since this seems more correct. This won't
actually affect anything, because gnome-shell just ignores the
CANCELLED status, but in theory it's nice to end things with an
indication that we are finished. Otherwise, CANCELLED will never be
emitted.)

Closes https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/7790

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3813>
(cherry picked from commit f9c41ea665dc0dd175ba5933c867c4551c4acf95)

js/portalHelper/main.js

index 5ae536c3b6a519857bc7c71a7a950f07821e3497..af49d51a40cba66241cba1abe85dbe3e9f070844 100644 (file)
@@ -134,7 +134,7 @@ class PortalWindow extends Gtk.ApplicationWindow {
         this._originalUrl = url;
         this._statusChangedCallback = statusChangedCallback;
         this._lastRecheck = 0;
-        this._recheckAtExit = false;
+        this._recheckTimeoutId = 0;
 
         this._networkSession = WebKit.NetworkSession.new_ephemeral();
         this._networkSession.set_proxy_settings(WebKit.NetworkProxyMode.NO_PROXY, null);
@@ -180,10 +180,12 @@ class PortalWindow extends Gtk.ApplicationWindow {
     }
 
     vfunc_close_request() {
-        if (this._recheckAtExit)
+        if (this._recheckTimeoutId) {
             this._statusChangedCallback(PortalHelperResult.RECHECK);
-        else
-            this._statusChangedCallback(PortalHelperResult.CANCELLED);
+            GLib.source_remove(this._recheckTimeoutId);
+            this._recheckTimeoutId = 0;
+        }
+        this._statusChangedCallback(PortalHelperResult.CANCELLED);
         return false;
     }
 
@@ -254,23 +256,24 @@ class PortalWindow extends Gtk.ApplicationWindow {
         // (but ratelimit the checks, we don't want to spam
         // nmcheck.gnome.org for portals that have 10 or more internal
         // redirects - and unfortunately they exist)
-        // If we hit the rate limit, we also queue a recheck
-        // when the window is closed, just in case we miss the
-        // final check and don't realize we're connected
-        // This should not be a problem in the cancelled logic,
-        // because if the user doesn't want to start the login,
-        // we should not see any redirect at all, outside this._uri
-
-        let now = GLib.get_monotonic_time();
-        let shouldRecheck = (now - this._lastRecheck) >
-            CONNECTIVITY_RECHECK_RATELIMIT_TIMEOUT;
-
-        if (shouldRecheck) {
-            this._lastRecheck = now;
-            this._recheckAtExit = false;
-            this._statusChangedCallback(PortalHelperResult.RECHECK);
-        } else {
-            this._recheckAtExit = true;
+
+        if (this._recheckTimeoutId === 0) {
+            const now = GLib.get_monotonic_time();
+            const timeSinceLastRecheck = this._lastRecheck ? now - this._lastRecheck : 0;
+
+            if (timeSinceLastRecheck > CONNECTIVITY_RECHECK_RATELIMIT_TIMEOUT || this._lastRecheck === 0) {
+                this._lastRecheck = now;
+                this._statusChangedCallback(PortalHelperResult.RECHECK);
+            } else {
+                const seconds =
+                    (CONNECTIVITY_RECHECK_RATELIMIT_TIMEOUT - timeSinceLastRecheck) /
+                    GLib.USEC_PER_SEC;
+                this._recheckTimeoutId = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, seconds, () => {
+                    this._statusChangedCallback(PortalHelperResult.RECHECK);
+                    this._recheckTimeoutId = 0;
+                    return GLib.SOURCE_REMOVE;
+                });
+            }
         }
 
         // Update the URI, in case of chained redirects, so we still